
*-----------------------------------------------------------------------------
// Figure D5: The effects of bus lane on car ownership, before and after the BEV expansion
*-----------------------------------------------------------------------------

*------------------------------
// Step 1: The file "Figure4.do" must be ran in order to store the right 
// estimation results as .ster files
*------------------------------


*------------------------------
// Step 2: Load estimates
*------------------------------

capt eststo drop *
capt estimates drop *

** Select variables to loop over: 
local yearlist  	  2015_2017  2008_2010  
local outcomelist     BEV_fam_yes  ICE_fam_count  car_fam_count car_fam_yes
local treatvar1list   toll_fam_mean     
local treatvar2list   ptl_fam_km_mean    

foreach outcome in `outcomelist'{
	foreach treatvar1 in `treatvar1list'{
		foreach treatvar2 in `treatvar2list'{
			foreach y in `yearlist' {
				* Results for couples
				estimates use "${ster}reg_g4_`y'_O_`outcome'_T1_`treatvar1'_T2_`treatvar2'_couple1" 
				eststo c_`y'_`outcome'
				* Results for singles
				estimates use "${ster}reg_g4_`y'_O_`outcome'_T1_`treatvar1'_T2_`treatvar2'_couple0" 
				eststo s_`y'_`outcome'
			}
		}
	}
}

estimates dir


*------------------------------
// Step 3: Plot coefficients
*------------------------------

local treatvarlist   ptl_fam_km_mean   
local hhtypelist c s

foreach hhtype in `hhtypelist'{
	foreach treatvar in `treatvarlist'{
			
			
		if "`treatvar'"=="ptl_fam_km_mean" {
			local xlab "xlab(-0.02(0.005)0.005)"
		}	

		if "`hhtype'"=="c" {
			local fig a
		}

		if "`hhtype'"=="s" {
			local fig b
		}

		coefplot ///
			(`hhtype'_2008_2010_BEV_fam_yes, msym(O) mcol(navy) ciopts(lcol(navy))) ///
			(`hhtype'_2015_2017_BEV_fam_yes, msym(O) mcol(navy) ciopts(lcol(navy))) ///
			(`hhtype'_2008_2010_car_fam_yes, msym(S) mcol(green) ciopts(lcol(green))) ///
			(`hhtype'_2015_2017_car_fam_yes, msym(S) mcol(green) ciopts(lcol(green))) ///
			(`hhtype'_2008_2010_ICE_fam_count, msym(T) mcol(red) ciopts(lcol(red))) ///
			(`hhtype'_2015_2017_ICE_fam_count, msym(T) mcol(red) ciopts(lcol(red))) ///
			(`hhtype'_2008_2010_car_fam_count, msym(D) mcol(brown) ciopts(lcol(brown))) ///
			(`hhtype'_2015_2017_car_fam_count, msym(D) mcol(brown) ciopts(lcol(brown))) ///
			, keep(`treatvar'*)  aseq swapnames legend(off) `xlab' xline(0, lcol(gs6) lpattern(dash))  ///
			headings(`hhtype'_2008_2010_BEV_fam_yes = "{bf:BEV (yes=1)}" ///
			 `hhtype'_2008_2010_car_fam_yes = "{bf:Car (yes=1)}" ///
			 `hhtype'_2008_2010_ICE_fam_count  = "{bf:ICEVs}" ///
			 `hhtype'_2008_2010_car_fam_count = "{bf:Cars}"  ) ///
			coeflabels(*2008_2010*="08-10"  *2015_2017*="15-17")  ///
			graphregion(color(white)) plotregion(lcolor(black)) scale(1.3) ///
			name(figD5`fig', replace)

		graph export    "${figures}FigureD5`fig'.pdf" ,  replace
		graph export    "${figures}FigureD5`fig'.png" ,  replace
	}
}


